package com.kaifamiao.stock.service.impl;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.kaifamiao.stock.domain.Stock;
import com.kaifamiao.stock.mapper.StockMapper;
import com.kaifamiao.stock.service.StockService;

import java.util.Date;
import java.util.List;

@Service
public class StockServiceImpl implements StockService {

    @Resource
    private StockMapper stockMapper;

    @Override
    public int insert(Stock record) {
        return stockMapper.insert(record);
    }

    @Override
    public int insertSelective(Stock record) {
        return stockMapper.insertSelective(record);
    }

    @Override
    public List<Stock> selectAll() {
        return stockMapper.selectAll();
    }

    @Override
    public List<Stock> selectByName(String code) {
        return stockMapper.selectByCode(code);
    }

    @Override
    public List<Stock> selectByAllName() {
        return stockMapper.selectByAllName();
    }

    @Override
    public List<Stock> selectByEndTime(String code, Date date) {
//        2022-10-11 00:00:00
//        String years = date.substring(0,date.indexOf("-")+1);
//        Integer mouths = Integer.parseInt(date.substring(date.indexOf("-")+1, date.lastIndexOf("-")))-2;
//        String days = date.substring(date.lastIndexOf("-"));
//        String startTime = years + mouths + days;
//        System.out.println("startTime = " + startTime);
//        return stockMapper.selectByEndTime(code, startTime, date);
        return stockMapper.selectByTime(code, date);
    }
}

